// base
import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
// redux
import { connect } from '@tarojs/redux'
import { DOREQUESTNEWEDUCATIONAINFORMATION } from './store/actions/pageneweducationainformation'
import { UPDATEPAGENEWEDUCATIONAINFORMATION } from './store/types/pageneweducationainformation'
// less
import './index.less'

// componnet
import EducationCard from '../../components/page-components/education-card'
import { navigateTo } from '../../crossplatform/apiservice/navigate'
import pagejumplist from '../../configuration/pagejumplist.json'
import BtmFixedBtn from '../../components/page-components/btm-fixed-btn'

const mapActiontoProps = dispatch => ({
  updateState (payload) {
    dispatch({
      type: UPDATEPAGENEWEDUCATIONAINFORMATION,
      payload: {
        ...payload
      }
    })
  },
  dorequest (payload) {
    return new Promise(resolve => {
      let promise = DOREQUESTNEWEDUCATIONAINFORMATION(payload)
      dispatch(promise)
      promise.payload.then(data => {
        resolve(data)
      })
    })
  }
})

@connect(
  ({ pageneweducationainformation, userinfo }) => ({
    ...pageneweducationainformation,
    userId: userinfo.userId
  }),
  mapActiontoProps
)
class NewEducationaInformation extends Component {
  config = {
    navigationBarTitleText: '教育信息'
  }

  componentWillMount () {
    // onLoad
  }

  componentDidMount () {
    // onready
  }

  componentDidShow () {
    // onshow
    this.queryWrap()
  }

  componentDidHide () {
    // onhide
  }

  componentWillUnmount () {
    // onUnload
  }

  queryWrap = () => {
    const { userId } = this.props
    this.props.dorequest({ userId })
  }

  jumpTo = id => {
    navigateTo({
      url: `${pagejumplist['education-information'].path}?id=${id}`
    })
  }

  onTap = () => {
    navigateTo({
      url: pagejumplist['education-information'].path
    })
  }

  render () {
    const { educationInformation } = this.props
    return (
      <View className="NewEducationaInformation_id83181">
        <View className="title">教育信息</View>
        {educationInformation.map((data, index) => {
          return (
            <View className="card" key={index}>
              <EducationCard onTap={this.jumpTo} dataSource={data} />
            </View>
          )
        })}
        <BtmFixedBtn text="添加教育信息" onTap={this.onTap} />
      </View>
    )
  }
}

export default NewEducationaInformation
